package com.example.day15;

import android.app.Activity;
import android.graphics.Bitmap;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;
import java.util.Map;

public class MyAdapter2 extends BaseAdapter {

    private Activity activity;
    private List<Map<String,Object>> dataList;

    public  MyAdapter2(Activity activity,List<Map<String,Object>> dataList){
        this.activity = activity;
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Log.e("###MyListViewBase", "getView " + position + " " + convertView);
        ViewHolder viewHolder=null;
        if(convertView==null){
            convertView = View.inflate(activity,R.layout.test_item,null);
            viewHolder=new ViewHolder();
            viewHolder.textViewthree =convertView.findViewById(R.id.text2);
            viewHolder.textViewtwo =convertView.findViewById(R.id.text1);
            viewHolder.imageone =convertView.findViewById(R.id.image1);
            convertView.setTag(viewHolder);
        }else{
            viewHolder=(ViewHolder)convertView.getTag();
        }
        Map<String,Object> map = dataList.get(position);
        viewHolder.imageone.setImageBitmap((Bitmap) map.get("pic"));
        viewHolder.textViewtwo.setText(map.get("title").toString());
        viewHolder.textViewthree.setText(map.get("food_str").toString());

        return convertView;
    }
    public class ViewHolder{
        ImageView imageone;
        TextView textViewtwo;
        TextView textViewthree;
    }
}
